﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library;
using Lamex.Interface;
using Lamex.Common;

namespace Lamex.mCost.UI
{
    public partial class frmCOST_Data_Query : frmBaseChild
    {
        string strSql;
        DataTable dt;

        public frmCOST_Data_Query()
        {
            InitializeComponent();
        }

        private void frmCOST_Data_Query_Load(object sender, EventArgs e)
        {
            try { base.InitButtons(); } catch { }//初始化标准功能，因要应用于RibbonForm，所以加入异常处理
        }

        private void sbtnView_Click(object sender, EventArgs e)
        {
            string strCurUser = Loginer.CurrentUser.AccountName;
            if (strCurUser == "何应书" || strCurUser == "刘邦泉" || strCurUser == "陈子锐")
            {
                getData();
            }
            else
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("非授权用户", "提示", MessageBoxButtons.OK);
            }
        }
        private void getData()
        {
            //string strToday = DateTime.Now.AddDays(-31).ToString("yyyy-MM-dd");
            if (radioGroup1.SelectedIndex == 0)
            {
                strSql = @"SELECT a.BUDAT AS 计划生产日期,a.AUFNR AS MO编号,a.MATNR AS 物料号,a.TP_TYPE AS TP类型,
a.TP_PRICE AS TP单价,a.PROD_LINE AS 生产线,a.MISS_MAT AS 无COST物料,a.ERR_INFO AS 异常信息,
a.UPDATE_TIME AS 更新时间,b.UPDATE_USER AS 创建用户
FROM Transfer_Package_MO_TP a,[172.23.134.36].[LamexMESManager].[dbo].[Transfer_Package_MO_TP] b
WHERE a.AUFNR=b.AUFNR";
            }
            else if (radioGroup1.SelectedIndex == 1)
            {
                strSql = @"SELECT COST_DATE AS 计薪日期,COST_FACTORY AS 分厂,BASIC_SALARY AS 日出勤工资,
DAILY_BONUS AS 当日奖金,TEMPORARY_COST AS 临时工工资,OT1_COST AS 加班一金额,
OT2_COST AS 加班二金额,ALLOWANCE AS 津贴,LABOR_TIME AS 生产工时,NET_PAY_COST AS 实发工资,
UPDATE_TIME AS 更新时间,UPDATE_USER AS 更新用户,FILE_NAME AS 源文件,CREATED_TIME AS 创建时间,EDITED_TIME AS 修改时间
FROM Cost_Labor_Comp_Daily";
            }
            else if (radioGroup1.SelectedIndex == 2)
            {
                strSql = @"SELECT COST_MONTH AS 成本月份,COST_FACTORY AS 分厂,SI_NUMBER AS 社保人数,SI_COST AS 社保金额,
HPF_NUMBER AS 公积金人数,HPF_COST AS 公积金金额,UPDATE_TIME AS 更新时间,UPDATE_USER AS 更新用户,
FILE_NAME AS 源文件,CREATED_TIME AS 创建时间,EDITED_TIME AS 修改时间
FROM Cost_Social_Insurance_Monthly";
            }

            //dt = Lamex.Base.BaseBuildSql.GetDataTableBySql(strSql);
            dt = Lamex.Common.DataBaseHelper_41.GetDataTableBySql(strSql);

            gridView1.Columns.Clear();
            gridControl1.DataSource = dt;

            gridView1.OptionsBehavior.Editable = false;
            gridView1.OptionsView.ColumnAutoWidth = true;
            //gridView1页脚汇总设置
            //gridView1.Columns[0].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count;
            //gridView1.Columns[0].SummaryItem.DisplayFormat = "计数:";
            //gridView1.Columns[1].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count;
            ////gridView1.Columns[1].SummaryItem.DisplayFormat = "{0:N}";//两位小数
            //gridView1.Columns[1].SummaryItem.DisplayFormat = "{0:N0}";//无小数位

        }
        public override void DoView(IButtonInfo sender)
        {
            sbtnView_Click(null, null);
            base.DoView(sender);
        }
    }
}